# -*-coding:utf-8 -*-

"""
# File       : zhihu.py
# Time       :2022/7/27 11:38
# Author     :zhengyong
# Description:
"""

import requests
from bs4 import BeautifulSoup
import re


def getZhihuQuesHot(url, headers):
    response = requests.get(url, headers=headers)
    soup = BeautifulSoup(response.text, "html.parser")
    questionsList = []
    host = 'https://tophub.today'
    for tr in soup.find_all('tr'):
        tds = tr.find_all('td')
        index = re.findall(r'\d{1,2}', str(tds[0]))[0]
        questionLink = tds[1].find_all('a', href=True)[0]['href']
        question = tds[1].find_all('a')[0].string
        tepmHotNum = re.findall(r'\d{1,8}', str(tds[2]))
        hotNum = tepmHotNum[0] if len(tepmHotNum) > 0 else '0'
        tempQuestion = [index, hotNum, question, host + questionLink]
        questionsList.append(tempQuestion)
    questionsList.append(tempQuestion)
    return questionsList


def getZhihuHots():
    url = 'https://tophub.today/n/mproPpoq6O'
    headers = {
        'user-agent': '',
        'cookie': '',
    }
    zhihudata = getZhihuQuesHot(url, headers)
    return zhihudata


if __name__ == '__main__':
    print(getZhihuHots())